home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 326-350 / disk_333 / multiplot / source / mplot_src / file.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  21KB  |  699 lines

  1. #include <graphics/display.h>
  2. #include <libraries/dosextens.h>
  3. #include <libraries/diskfont.h>
  4. #include <exec/exec.h>
  5. #include <intuition/intuitionbase.h>
  6. #include <graphics/regions.h>
  7. #include <devices/keymap.h>
  8. #include <stdio.h>
  9. #include <workbench/startup.h>
  10. #include <graphics/gfxmacros.h>
  11. #include <graphics/gfxbase.h>
  12. #include <math.h>
  13.  
  14. #include "diskicon.h"
  15. #include "struct.h"
  16. #include "plotlim.h"
  17. #include "ffp.h"
  18.  
  19.  
  20. extern int MAXVERT;
  21. extern int MAXHORIZ;
  22.  
  23.  
  24. extern int GetDat();
  25. extern void plot();
  26. extern struct Screen *screen;
  27. extern struct NewScreen newscreen;
  28. extern struct NewWindow newwindow;
  29. extern struct Window *window;
  30. extern int XMINP;      /* LMARGIN */
  31. extern int YMAXP;   /* MAXVERT - TMARGIN */
  32. extern int YMINP;    /* BMARGIN */
  33. extern int XMAXP;
  34.  
  35.  
  36.  
  37. #define QUIT 0
  38. #define GO 1
  39. extern int QuitFlag;
  40.  
  41. extern long IconBase;
  42.  
  43. extern FFP xtic[MAXTICS],ytic[MAXTICS];
  44. extern short xticp[MAXTICS],yticp[MAXTICS];
  45. extern char filename[150];
  46. extern struct RastPort *p;
  47. extern struct ViewPort *vp;
  48.  
  49. #define P_X_TIC_SIZE X_TIC_SIZE*(P_YREG/MAXVERT)
  50. #define P_Y_TIC_SIZE Y_TIC_SIZE*(P_XREG/MAXHORIZ)
  51. #define P_ERR_DELIM ERR_DELIM*(P_XREG/MAXHORIZ)
  52. #define P_CH_WID 100
  53. #define P_CH_HEI 150
  54.  
  55. int P_LMARGIN;
  56. int P_BMARGIN;
  57. int P_TMARGIN;
  58. int P_RMARGIN;
  59. int P_YREG;
  60. int P_XREG;
  61.  
  62. #define MCAD_ERR_DELIM ERR_DELIM*(
  63.  
  64. static FFP XScale, YScale, XOffset, YOffset;
  65.  
  66. void fWrtFFP(fp, ffpval)
  67. FILE *fp;
  68. FFP ffpval;
  69. {
  70.    fprintf(fp, "%d", (int)ffpval);
  71. }
  72.  
  73.  
  74. void WrtAxes(fp, Tics, Grid, XLabel,YLabel,Title)
  75. FILE *fp;
  76. struct Tics *Tics;
  77. short Grid;
  78. char *XLabel;
  79. char *YLabel;
  80. char *Title;
  81.  
  82. {
  83.    short n, tmpx, tmpy, i;
  84.    FFP *x, *y;
  85.    char tmpstr[20];
  86.  
  87.    /*** DRAW TICS/GRID ***/
  88.    fprintf(fp,"SP2;");
  89.    x=Tics->x; y=Tics->y;
  90.    for (i=0; i < Tics->NX; i++) {
  91.       if (Grid) {
  92.          fprintf(fp,"PU"); fWrtFFP(fp,(XScale * (XOffset + x[i])));
  93.          fprintf(fp," %d;PD",P_BMARGIN);
  94.          fWrtFFP(fp,(XScale * (XOffset + x[i])));
  95.          fprintf(fp," %d;\n",P_YREG);
  96.       }
  97.       else {
  98.          fprintf(fp,"PU"); fWrtFFP(fp,(XScale * (XOffset + x[i])));
  99.          fprintf(fp," %d;PD",P_BMARGIN);
  100.          fWrtFFP(fp,(XScale * (XOffset + x[i])));
  101.          fprintf(fp," %d;",P_BMARGIN + P_X_TIC_SIZE);
  102.          fprintf(fp,"PU"); fWrtFFP(fp,(XScale * (XOffset + x[i])));
  103.          fprintf(fp," %d;PD",P_YREG);
  104.          fWrtFFP(fp,(XScale * (XOffset + x[i])));
  105.          fprintf(fp," %d;\n",P_YREG - P_X_TIC_SIZE);
  106.       }
  107.    }
  108.    for (i=0; i < Tics->NY; i++) {
  109.       if (Grid) {
  110.          fprintf(fp,"PU%d ",P_LMARGIN);
  111.          fWrtFFP(fp,(YScale * (YOffset + y[i])));
  112.          fprintf(fp,"PD%d ",P_XREG);
  113.          fWrtFFP(fp,(YScale * (YOffset + y[i])));
  114.          fprintf(fp,";\n");
  115.       }
  116.       else {
  117.          fprintf(fp,"PU%d ",P_LMARGIN);
  118.          fWrtFFP(fp,(YScale * (YOffset + y[i])));
  119.          fprintf(fp,";PD%d ", P_LMARGIN + P_Y_TIC_SIZE);
  120.          fWrtFFP(fp,(YScale * (YOffset + y[i])));
  121.          fprintf(fp,";");
  122.          fprintf(fp,"PU%d ",P_XREG);
  123.          fWrtFFP(fp,(YScale * (YOffset + y[i])));
  124.          fprintf(fp,";PD%d ", P_XREG - P_Y_TIC_SIZE);
  125.          fWrtFFP(fp,(YScale * (YOffset + y[i])));
  126.          fprintf(fp,";\n");
  127.       }
  128.    }
  129.  
  130.    /*** DRAW BORDER ***/
  131.    fprintf(fp,"SP1;PU%d %d;",P_LMARGIN,P_BMARGIN);
  132.    fprintf(fp,"PD%d %d %d %d %d %d %d %d;\n",P_XREG,P_BMARGIN,P_XREG,P_YREG,
  133.    P_LMARGIN,P_YREG,P_LMARGIN,P_BMARGIN);
  134.  
  135.  
  136.    /*** PRINT TIC VALUES ***/
  137.    fprintf(fp,"SP1;");
  138.    for (i=0; i < Tics->NX; i++) {
  139.       n=GetString(&tmpstr,Tics->x[i]);
  140.       tmpx = (short)((XScale * (XOffset + Tics->x[i])));
  141.       tmpx -= (((n+1)/2)-.5) * P_CH_WID;
  142.       tmpy = P_BMARGIN - (2*P_CH_HEI) +1;
  143.       fprintf(fp, "PU%d %d;", tmpx,tmpy);
  144.       fprintf(fp,"LB%s\003", tmpstr);
  145.    }
  146.    /* Write X Label */
  147.    if (XLabel!=NULL){
  148.       tmpx = 0.5 * P_XREG;
  149.       tmpx -= (((strlen(XLabel)+1)/2)-.5) * P_CH_WID;
  150.       tmpy= 1;
  151.       fprintf(fp, "PU%d %d;", tmpx,tmpy);
  152.    }  fprintf(fp,"LB%s\003", XLabel);
  153.  
  154.    /* Write Title */
  155.    if (Title!=NULL) {
  156.       tmpx = 0.5 * P_XREG;
  157.       tmpx -= (((strlen(Title)+1)/2)-.5) * P_CH_WID;
  158.       tmpy= P_YREG + P_CH_HEI - 1;
  159.       fprintf(fp, "PU%d %d;", tmpx,tmpy);
  160.       fprintf(fp,"LB%s\003", Title);
  161.    }
  162.  
  163.    for (i=0; i < Tics->NY; i++) {
  164.       n=GetString(&tmpstr,Tics->y[i]);
  165.       tmpy = (short)((YScale * (YOffset + Tics->y[i])));
  166.       tmpy -= .5 * P_CH_WID;
  167.       tmpx = P_LMARGIN-( (n+1) * P_CH_WID );
  168.       fprintf(fp, "PU%d %d;",tmpx, tmpy);
  169.       fprintf(fp,"LB%s\003", tmpstr);
  170.    }
  171.    /* Write YLabel */
  172.    if (YLabel!=NULL) {
  173.       fprintf(fp,"SR%f %f;\n",
  174.          (float)(100*P_CH_WID*4/3) / (P_XREG - P_LMARGIN - P_RMARGIN),
  175.          (float)(100*P_CH_HEI*3/4) / (P_YREG - P_BMARGIN));
  176.       tmpx = 1;
  177.       tmpy= 0.5 * P_YREG;
  178.       tmpy -= strlen(YLabel) * P_CH_WID ;
  179.       fprintf(fp, "DR0,1; PU%d %d;", tmpx,tmpy);
  180.       fprintf(fp,"LB%s\003", YLabel);
  181.    }
  182.  
  183. }
  184.  
  185. extern USHORT chip WaitSprite[];
  186. extern char *stpchr();
  187.  
  188. WrtPlt(Pict,Dest)
  189. USHORT Dest;
  190. struct Pict *Pict;
  191. {
  192. struct Process  *OurTask;
  193. struct Window   *old_pr_WindowPtr;
  194. FILE *fp;
  195. short i,n=3;
  196. struct Plot *Plot;
  197. FFP *x, *y, *e;
  198. short xptsiz, yptsiz;
  199. static char plotname[150], def_drive[150]="PLT:", def_path[100], def_node[30],def_extn[20];
  200. static char PlotNum = 0;
  201. void PlotBox(), PlotTri(), PlotEggs(), PlotPlus(), PlotKite();
  202. struct Tics *Tics;
  203. char tmpstr[20];
  204.  
  205.    if (Dest)
  206.       {
  207.           strcpy(plotname,filename);
  208.           strsfn(plotname,def_drive,def_path,def_node,def_extn);
  209.           strcat(def_drive,def_path);
  210.           strcat(def_node,".plt");
  211.           strcat(def_node,PlotNum);
  212.  
  213.           OurTask = (struct Process *)FindTask(0L);
  214.           old_pr_WindowPtr = (struct Window *)OurTask->pr_WindowPtr;
  215.           OurTask->pr_WindowPtr = (APTR)window;
  216.           if (get_fname(window,screen,"Save File As...",def_node,def_drive)==NULL)
  217.                {
  218.                   OurTask->pr_WindowPtr = (APTR)old_pr_WindowPtr;
  219.                   return(TRUE);
  220.                 }
  221.  
  222.            OurTask->pr_WindowPtr = (APTR)old_pr_WindowPtr;
  223.            strmfp(plotname,def_drive,def_node);
  224.            PutDiskObject(plotname,&IconDiskObject);
  225.        }
  226.    else
  227.        {
  228.           if (!(fp = fopen("l:plt-handler","r") ))
  229.              {
  230.                 Message("Printing needs the PLT: Device"); return(FALSE);
  231.              }
  232.           fclose(fp);
  233.  
  234.           Execute("c:failat >Nil: <Nil: 20 \n c:mount >Nil: <Nil: plt:",0,0);
  235.           strcpy(plotname,"PLT:");
  236.        }
  237.    if (!(fp = fopen(plotname,"w") ))
  238.       {Message("  Can't write file to PLT:"); return(FALSE);}
  239.    SetPointer(window,WaitSprite,26,14,-4,-4);
  240.    Tics = Pict->Tics;
  241.    for (i=0; i < Tics->NY; i++) { n=max(n,GetString(&tmpstr,Tics->y[i]));}
  242.    P_LMARGIN=(n+2)*P_CH_WID;
  243.    if (Pict->YLabel!=NULL) P_LMARGIN=P_LMARGIN+P_CH_HEI;
  244.    P_XREG = 10000;
  245.    if (Pict->XLabel!=NULL) P_BMARGIN = P_CH_HEI*4;
  246.    else P_BMARGIN = P_CH_HEI*2;
  247.    if (Pict->Title!=NULL) P_TMARGIN = P_CH_HEI*2;
  248.    else P_TMARGIN=0;
  249.    P_RMARGIN = 0;
  250.    P_YREG = 10000-P_TMARGIN;
  251.  
  252.    fprintf(fp,"IN;SC 0 %d 0 %d;\n", P_XREG+100, P_YREG+100+P_TMARGIN);
  253.    fprintf(fp,"VS 20.0;\n");  /* VELOCITY cm/s */
  254.    fprintf(fp,"\033.N;19:\033.I81;;17:\n"); /* XON/XOFF */
  255.    XScale = (FFP)(P_XREG - P_LMARGIN - P_RMARGIN) /
  256.             (Pict->CurrReg->XMax - Pict->CurrReg->XMin);
  257.    YScale = (FFP)(P_YREG - P_BMARGIN) /
  258.             (Pict->CurrReg->YMax - Pict->CurrReg->YMin);
  259.    XOffset = (FFP)(P_LMARGIN) / XScale - Pict->CurrReg->XMin;
  260.    YOffset = (FFP)(P_BMARGIN) / YScale - Pict->CurrReg->YMin;
  261.  
  262.    Plot = Pict->Plot;
  263.    while (Plot) {
  264.       if (Plot->Enabled) {
  265.          fprintf(fp,"PU;SP%d;\n", 1+Plot->Color-PLOTCOLORBASE);
  266.  
  267.          /* PLOT LINES */
  268.          if (Plot->Lines != FALSE) {
  269.             x=Plot->x; y=Plot->y;
  270.             fprintf(fp, "PU"); fWrtFFP(fp,(XScale * (XOffset + *x)));
  271.             fprintf(fp," ");
  272.             fWrtFFP(fp,(YScale * (YOffset + *y))); fprintf(fp,";");
  273.             x++; y++;
  274.             fprintf(fp, "PD");
  275.             for (i=1; i<Plot->NPts; i++, x++, y++) {
  276.                if (i>1) fprintf(fp, " ");
  277.                fWrtFFP(fp,(XScale * (XOffset + *x)));
  278.                fprintf(fp," ");
  279.                fWrtFFP(fp,(YScale * (YOffset + *y)));
  280.             }
  281.             fprintf(fp,";\n");
  282.          }
  283.  
  284.          /* PLOT POINTS */
  285.          if (Plot->PointSize != 0) {
  286.             xptsiz = abs(Plot->PointSize) * (P_XREG / 1100);
  287.             yptsiz = abs(Plot->PointSize) * (P_YREG / 850);
  288.             x=Plot->x; y=Plot->y;
  289.             for (i=0; i<Plot->NPts; i++, x++, y++) {
  290.                fprintf(fp,"PU");
  291.                fWrtFFP(fp,(XScale * (XOffset + *x)));
  292.                fprintf(fp," ");
  293.                fWrtFFP(fp,(YScale * (YOffset + *y)));
  294.                fprintf(fp,";");
  295.                switch (Plot->PointType) {
  296.                case 1:  PlotTri(fp,xptsiz/2,yptsiz/2);  break;
  297.                case 2:  PlotKite(fp,xptsiz/2,yptsiz/2); break;
  298.                case 3:  PlotEggs(fp,xptsiz/2,yptsiz/2); break;
  299.                case 4:  PlotEggs(fp,xptsiz/2,yptsiz/2); /* Fall through (fancy, huh?) */
  300.                case 5:  PlotPlus(fp,xptsiz/2,yptsiz/2); break;
  301.                case 6:
  302.                default: PlotBox(fp,xptsiz/2,yptsiz/2); break;
  303.                }
  304.             }
  305.          }
  306.  
  307.          /* PLOT ERROR BARS */
  308.          if (Pict->ShowErr) {
  309.             x=Plot->x; y=Plot->y; e=Plot->e;
  310.             for (i=0; i<Plot->NPts; i++, x++, y++, e++) {
  311.                if (*e > FFPSMALL)
  312.                  {
  313.                     fprintf(fp,"PU");
  314.                     fWrtFFP(fp,(XScale * (XOffset + *x)));
  315.                     fprintf(fp," ");
  316.                     fWrtFFP(fp,(YScale * (YOffset + (*y - *e))));
  317.                     fprintf(fp,"; PD");
  318.                     fWrtFFP(fp,(XScale * (XOffset + *x)));
  319.                     fprintf(fp," ");
  320.                     fWrtFFP(fp,(YScale * (YOffset + (*y + *e))));
  321.                     fprintf(fp,";\n");
  322.  
  323.                     /* PLOT DELIMITERS ON ERROR BARS */
  324.  
  325.                     fprintf(fp,"PU");
  326.                     fWrtFFP(fp,(XScale * (XOffset + *x) - P_ERR_DELIM));
  327.                     fprintf(fp," ");
  328.                     fWrtFFP(fp,(YScale * (YOffset + (*y - *e))));
  329.                     fprintf(fp,"; PD");
  330.                     fWrtFFP(fp,(XScale * (XOffset + *x)+ P_ERR_DELIM));
  331.                     fprintf(fp," ");
  332.                     fWrtFFP(fp,(YScale * (YOffset + (*y - *e))));
  333.                     fprintf(fp,";\n");
  334.                     fprintf(fp,"PU");
  335.                     fWrtFFP(fp,(XScale * (XOffset + *x) - P_ERR_DELIM));
  336.                     fprintf(fp," ");
  337.                     fWrtFFP(fp,(YScale * (YOffset + (*y + *e))));
  338.                     fprintf(fp,"; PD");
  339.                     fWrtFFP(fp,(XScale * (XOffset + *x)+ P_ERR_DELIM));
  340.                     fprintf(fp," ");
  341.                     fWrtFFP(fp,(YScale * (YOffset + (*y + *e))));
  342.                     fprintf(fp,";\n");
  343.                  }
  344.             }
  345.          }
  346.       }
  347.       Plot = Plot->NextPlot;
  348.    }
  349.  
  350.    fprintf(fp,"SR%f %f;\n",
  351.          (float)(100*P_CH_WID*3/4) / (P_XREG),
  352.          (float)(100*P_CH_HEI) / (P_YREG));
  353.    WrtAxes(fp, Pict->Tics, Pict->Grid, Pict->XLabel, Pict->YLabel, Pict->Title);
  354.  
  355.    fprintf(fp, "SP;");
  356.    (void) fclose(fp);
  357.    PlotNum++;
  358.    ClearPointer(window);
  359.    return(TRUE);
  360. }
  361.  
  362.  
  363.  
  364.  
  365. void header(n, c, t, fp)
  366. int n, c, t;
  367. FILE *fp;
  368. {
  369.    UBYTE bdummy;
  370.    bdummy = n;
  371.    fwrite((char *)&bdummy, 1, 1, fp);
  372.    bdummy = c;
  373.    fwrite((char *)&bdummy, 1, 1, fp);
  374.    bdummy = 0;
  375.    fwrite((char *)&bdummy, 1, 1, fp); /* LineType */
  376.    bdummy = t;
  377.    fwrite((char *)&bdummy, 1, 1, fp);
  378.    bdummy = 0;
  379.    fwrite((char *)&bdummy, 1, 1, fp); /* padding for future use */
  380.    fwrite((char *)&bdummy, 1, 1, fp);
  381. }
  382.  
  383. To_mCAD(Pict,Dest)
  384. struct Pict *Pict;
  385. USHORT Dest;
  386. {
  387.  
  388.    struct Process  *OurTask;
  389.    struct Window   *old_pr_WindowPtr;
  390.  
  391.    FILE *fp;
  392.    short i;
  393.    struct Plot *Plot;
  394.    FFP *x, *y, *e, xtmp, ytmp, xtmp1, ytmp1;
  395.    FFP xptsiz, yptsiz, XReg, YReg, XScale, XOffset;
  396.    char plotname[150], def_drive[150], def_path[100], def_node[30],def_extn[20];
  397.    static char mPlotNum = 0;
  398.    void CADBox(), CADKite(), CADTri(), CADEggs(), CADPlus();
  399.  
  400.   if (Dest)
  401.     {
  402.      strcpy(plotname,filename);
  403.      strsfn(plotname,def_drive,def_path,def_node,def_extn);
  404.      strcat(def_drive,def_path);
  405.      strcat(def_node,".txt");
  406.      strcat(def_node,mPlotNum);
  407.  
  408.            OurTask = (struct Process *)FindTask(0L);
  409.            old_pr_WindowPtr = (struct Window *)OurTask->pr_WindowPtr;
  410.            OurTask->pr_WindowPtr = (APTR)window;
  411.            if (get_fname(window,screen,"Save File As...",def_node,def_drive)==NULL)
  412.                {
  413.                   OurTask->pr_WindowPtr = (APTR)old_pr_WindowPtr;
  414.                   return(TRUE);
  415.                 }
  416.  
  417.      OurTask->pr_WindowPtr = (APTR)old_pr_WindowPtr;
  418.      strmfp(plotname,def_drive,def_node);
  419.      PutDiskObject(plotname,&IconDiskObject);
  420.     }
  421.    else
  422.        {
  423.           if (!(fp = fopen("T:tempfile","w") ))
  424.              {
  425.                 Message("Save needs the T: Device"); return(FALSE);
  426.              }
  427.           fclose(fp);
  428.           strcpy(plotname,"T:tempfile");
  429.        }
  430.  
  431.    if (!(fp = fopen(plotname,"w") ))
  432.       {Message("   Can't write tempory file  "); return(FALSE);}
  433.  
  434.    XReg = Pict->CurrReg->XMax - Pict->CurrReg->XMin;
  435.    YReg = Pict->CurrReg->YMax - Pict->CurrReg->YMin;
  436.    XScale = YReg/XReg * 1.4434; XOffset = Pict->CurrReg->XMin;
  437.  
  438.    Plot = Pict->Plot;
  439.    while (Plot) {
  440.       if (Plot->Enabled) {
  441.  
  442.          /* PLOT LINES */
  443.          if (Plot->Lines != FALSE) {
  444.             x=Plot->x; y=Plot->y;
  445.             for (i=0; i<Plot->NPts; i++, x++, y++) {
  446.                xtmp = XScale * (*x - XOffset);
  447.                fprintf(fp, "%f %f\n", xtmp, *y);
  448.             }
  449.             fprintf(fp,"*>\n*C %d\n\n", 1+Plot->Color-PLOTCOLORBASE);
  450.          }
  451.  
  452.          /* PLOT POINTS */
  453.          if (Plot->PointSize != 0) {
  454.             xptsiz = abs(Plot->PointSize) * (XReg / 582.);
  455.             xptsiz = XScale * xptsiz;
  456.             yptsiz = abs(Plot->PointSize) * (YReg / 360.);
  457.             x=Plot->x; y=Plot->y;
  458.             for (i=0; i<Plot->NPts; i++, x++, y++) {
  459.                switch (Plot->PointType) {
  460.                case 1:  CADTri(fp,Plot,(XScale * (*x - XOffset)),*y,xptsiz/2,yptsiz/2); break;
  461.                case 2:  CADKite(fp,Plot,(XScale * (*x - XOffset)),*y,xptsiz/2,yptsiz/2); break;
  462.                case 3:  CADEggs(fp,Plot,(XScale * (*x - XOffset)),*y,xptsiz/2,yptsiz/2); break;
  463.                case 4:  CADEggs(fp,Plot,(XScale * (*x - XOffset)),*y,xptsiz/2,yptsiz/2);
  464.                case 5:  CADPlus(fp,Plot,(XScale * (*x - XOffset)),*y,xptsiz/2,yptsiz/2); break;
  465.                case 6:
  466.                default: CADBox(fp,Plot,(XScale * (*x - XOffset)),*y,xptsiz/2,yptsiz/2); break;
  467.                }
  468.             }
  469.          }
  470.  
  471.          /* PLOT ERROR BARS */
  472.          if (Pict->ShowErr) {
  473.             x=Plot->x; y=Plot->y; e=Plot->e;
  474.             xtmp1=XScale*(ERR_DELIM*(XReg/582));     /* SCALED ERROR DELIMITER */
  475.             for (i=0; i<Plot->NPts; i++, x++, y++, e++) {
  476.               if (*e > FFPSMALL)
  477.                 {
  478.                    xtmp = XScale * (*x - XOffset);
  479.                    ytmp = *y - *e;
  480.                    fprintf(fp,"%f %f\n",xtmp-xtmp1,ytmp);
  481.                    fprintf(fp,"%f %f\n*>\n*C %d\n\n",xtmp+xtmp1,ytmp,1+Plot->Color-PLOTCOLORBASE);
  482.                    fprintf(fp,"%f %f\n", xtmp, ytmp);
  483.                    ytmp = *y + *e;
  484.                    fprintf(fp,"%f %f\n", xtmp, ytmp);
  485.                    fprintf(fp,"*>\n*C %d\n\n", 1+Plot->Color-PLOTCOLORBASE);
  486.                    fprintf(fp,"%f %f\n",xtmp-xtmp1,ytmp);
  487.                    fprintf(fp,"%f %f\n*>\n*C %d\n\n",xtmp+xtmp1,ytmp,1+Plot->Color-PLOTCOLORBASE);
  488.                 }
  489.             }
  490.          }
  491.       }
  492.       Plot = Plot->NextPlot;
  493.    }
  494.  
  495.    /*** DRAW TICS/GRID ***/
  496.    x = Pict->Tics->x; y = Pict->Tics->y;
  497.    for (i=0; i < Pict->Tics->NX; i++) {
  498.       xtmp = XScale * (x[i] - XOffset);
  499.       if (Pict->Grid) {
  500.          PToU(Pict, 0, YMINP, &xtmp1, &ytmp);
  501.          PToU(Pict, 0, YMAXP, &xtmp1, &ytmp1);
  502.          fprintf(fp,"%f %f\n%f %f\n*>\n*C 2\n\n", xtmp, ytmp, xtmp, ytmp1);
  503.       }
  504.       else {
  505.          PToU(Pict, 0, YMINP, &xtmp1, &ytmp);
  506.          fprintf(fp,"%f %f\n", xtmp, ytmp);
  507.          PToU(Pict, 0, YMINP+X_TIC_SIZE, &xtmp1, &ytmp1);
  508.          fprintf(fp,"%f %f\n*>\n*C 3\n\n", xtmp, ytmp1);
  509.          PToU(Pict, 0, YMAXP, &xtmp1, &ytmp);
  510.          fprintf(fp,"%f %f\n", xtmp, ytmp);
  511.          PToU(Pict, 0, YMAXP-X_TIC_SIZE, &xtmp1, &ytmp1);
  512.          fprintf(fp,"%f %f\n*>\n*C 3\n\n", xtmp, ytmp1);
  513.       }
  514.    }
  515.    for (i=0; i < Pict->Tics->NY; i++) {
  516.       if (Pict->Grid) {
  517.          PToU(Pict, XMINP, YMINP, &xtmp, &ytmp);
  518.          xtmp = XScale * (xtmp - XOffset);
  519.          PToU(Pict, XMAXP, YMAXP, &xtmp1, &ytmp1);
  520.          xtmp1 = XScale * (xtmp1 - XOffset);
  521.          fprintf(fp,"%f %f\n%f %f\n*>\n*C 2\n\n", xtmp, y[i], xtmp1, y[i]);
  522.       }
  523.       else {
  524.          PToU(Pict, XMINP, 0, &xtmp, &ytmp);
  525.          xtmp = XScale * (xtmp - XOffset);
  526.          fprintf(fp,"%f %f\n", xtmp, y[i]);
  527.          PToU(Pict, XMINP+Y_TIC_SIZE, 0, &xtmp1, &ytmp1);
  528.          xtmp1 = XScale * (xtmp1 - XOffset);
  529.          fprintf(fp,"%f %f\n*>\n*C 3\n\n", xtmp1, y[i]);
  530.          PToU(Pict, XMAXP, 0, &xtmp, &ytmp);
  531.          xtmp = XScale * (xtmp - XOffset);
  532.          fprintf(fp,"%f %f\n", xtmp, y[i]);
  533.          PToU(Pict, XMAXP-Y_TIC_SIZE, 0, &xtmp1, &ytmp1);
  534.          xtmp1 = XScale * (xtmp1 - XOffset);
  535.          fprintf(fp,"%f %f\n*>\n*C 3\n\n", xtmp1, y[i]);
  536.       }
  537.    }
  538.  
  539.    /*** PRINT TIC VALUES ***/
  540. /*
  541. *   for (i=0; i < Pict->Tics->NX; i++) {
  542. *      n = sprintf(tmpstr, "%-.4f", Pict->Tics->x[i]);
  543. *      n = min(n, 7);
  544. *      while (tmpstr[n-1] == '0') n--;
  545. *      tmpstr[n]=0;
  546. *   }
  547. *   for (i=0; i < Pict->Tics->NY; i++) {
  548. *      n = sprintf(tmpstr, "%-.4f", Pict->Tics->y[i]);
  549. *      n = min(n, 7);
  550. *      while (tmpstr[n-1] == '0') n--;
  551. *      tmpstr[n]=0;
  552. *   }
  553. */
  554.  
  555.    /*** DRAW AXES ***/
  556.    PToU(Pict, XMINP, YMINP, &xtmp, &ytmp);
  557.    xtmp = XScale * (xtmp - XOffset);
  558.    PToU(Pict, XMAXP, YMAXP, &xtmp1, &ytmp1);
  559.    xtmp1 = XScale * (xtmp1 - XOffset);
  560.    fprintf(fp, "%f %f\n", xtmp, ytmp);
  561.    fprintf(fp, "%f %f\n", xtmp1, ytmp);
  562.    fprintf(fp, "%f %f\n", xtmp1, ytmp1);
  563.    fprintf(fp, "%f %f\n", xtmp, ytmp1);
  564.    fprintf(fp, "%f %f\n", xtmp, ytmp);
  565.    fprintf(fp,"*C 1\n\n");
  566.  
  567.    (void) fclose(fp);
  568.    mPlotNum++;
  569.    return(TRUE);
  570. }
  571.  
  572.  
  573. void PlotPlus(fp,x,y)
  574. FILE *fp;
  575. SHORT x,y;
  576. {
  577.    fprintf(fp,"PR %d 0;",-x);
  578.    fprintf(fp,"PD %d 0;",2*x);
  579.    fprintf(fp,"PU %d %d;",-x,-y);
  580.    fprintf(fp,"PD 0 %d;PA;",2*y);
  581. }
  582.  
  583. void PlotBox(fp,x,y)
  584. FILE *fp;
  585. SHORT x,y;
  586. {
  587.    fprintf(fp,"PR%d %d;", -x, -y);
  588.    fprintf(fp,"PD%d 0 0 %d %d 0 0 %d;PA;\n",2*x,2*y, -2*x, -2*y);
  589. }
  590.  
  591. void PlotEggs(fp,x,y)
  592. FILE *fp;
  593. SHORT x,y;
  594. {
  595.    fprintf(fp,"PR %d %d;",-x,-y);
  596.    fprintf(fp,"PD %d %d;",2*x,2*y);
  597.    fprintf(fp,"PU 0 %d;",-2*y);
  598.    fprintf(fp,"PD %d %d;",-2*x,2*y);
  599.    fprintf(fp,"PU %d %d;PA\n;",x,-y);
  600. }
  601.  
  602.  
  603. void PlotKite(fp,x,y)
  604. FILE *fp;
  605. SHORT x,y;
  606. {
  607.    fprintf(fp,"PR%d 0;",-x);
  608.    fprintf(fp,"PD%d %d %d %d %d %d %d %d;PA;\n",x,y,x,-y,-x,-y,-x,y);
  609. }
  610.  
  611.  
  612. void PlotTri(fp,x,y)
  613. FILE *fp;
  614. SHORT x,y;
  615. {
  616.    fprintf(fp,"PR%d %d;", -x, -y);
  617.    fprintf(fp,"PD%d %d %d %d %d 0;PA;\n",x,2*y,x,-2*y,-2*x);
  618.  
  619. }
  620.  
  621.  
  622. void CADBox(fp,Plot,x,y,dx,dy)
  623. FILE *fp;
  624. struct Plot *Plot;
  625. FFP x,y,dx,dy;
  626. {
  627.    x = x - dx;
  628.    y = y - dy;
  629.    fprintf(fp,"%f %f\n", x, y); x += 2*dx;
  630.    fprintf(fp,"%f %f\n", x, y); y += 2*dy;
  631.    fprintf(fp,"%f %f\n", x, y); x -= 2*dx;
  632.    fprintf(fp,"%f %f\n", x, y); y -= 2*dy;
  633.    fprintf(fp,"%f %f\n", x, y);
  634.    fprintf(fp,"*>\n*C %d\n\n", 1+Plot->Color-PLOTCOLORBASE);
  635.  
  636. }
  637.  
  638. void CADPlus(fp,Plot,x,y,dx,dy)
  639. FILE *fp;
  640. struct Plot *Plot;
  641. FFP x,y,dx,dy;
  642. {
  643.    x = x - dx;
  644.    fprintf(fp,"%f %f\n", x, y); x += 2*dx;
  645.    fprintf(fp,"%f %f\n", x, y);
  646.    fprintf(fp,"*>\n*C %d\n\n", 1+Plot->Color-PLOTCOLORBASE);
  647.  
  648.    x -= dx; y -= dy;
  649.    fprintf(fp,"%f %f\n", x, y); y += 2*dy;
  650.    fprintf(fp,"%f %f\n", x, y);
  651.    fprintf(fp,"*>\n*C %d\n\n", 1+Plot->Color-PLOTCOLORBASE);
  652. }
  653.  
  654. void CADEggs(fp,Plot,x,y,dx,dy)
  655. FILE *fp;
  656. struct Plot *Plot;
  657. FFP x,y,dx,dy;
  658. {
  659.    x = x - dx; y = y - dy;
  660.    fprintf(fp,"%f %f\n", x, y); x += 2*dx; y += 2*dy;
  661.    fprintf(fp,"%f %f\n", x, y);
  662.    fprintf(fp,"*>\n*C %d\n\n", 1+Plot->Color-PLOTCOLORBASE);
  663.  
  664.    y -= 2*dy;
  665.    fprintf(fp,"%f %f\n", x, y); x -= 2*dx; y += 2*dy;
  666.    fprintf(fp,"%f %f\n", x, y);
  667.    fprintf(fp,"*>\n*C %d\n\n", 1+Plot->Color-PLOTCOLORBASE);
  668. }
  669.  
  670.  
  671. void CADKite(fp,Plot,x,y,dx,dy)
  672. FILE *fp;
  673. struct Plot *Plot;
  674. FFP x,y,dx,dy;
  675. {
  676.    x = x - dx;
  677.    fprintf(fp,"%f %f\n", x, y); x += dx; y += dy;
  678.    fprintf(fp,"%f %f\n", x, y); x += dx; y -= dy;
  679.    fprintf(fp,"%f %f\n", x, y); x -= dx; y -= dy;
  680.    fprintf(fp,"%f %f\n", x, y); x -= dx; y += dy;
  681.    fprintf(fp,"%f %f\n", x, y);
  682.    fprintf(fp,"*>\n*C %d\n\n", 1+Plot->Color-PLOTCOLORBASE);
  683. }
  684.  
  685. void CADTri(fp,Plot,x,y,dx,dy)
  686. FILE *fp;
  687. struct Plot *Plot;
  688. FFP x,y,dx,dy;
  689. {
  690.    x = x - dx;
  691.    y = y - dy;
  692.    fprintf(fp,"%f %f\n", x, y); x += dx; y += 2*dy;
  693.    fprintf(fp,"%f %f\n", x, y); x += dx; y -= 2*dy;
  694.    fprintf(fp,"%f %f\n", x, y); x -= 2*dy;
  695.    fprintf(fp,"%f %f\n", x, y);
  696.    fprintf(fp,"*>\n*C %d\n\n", 1+Plot->Color-PLOTCOLORBASE);
  697. }
  698.  
  699.